#ifndef STREAM_IO_HPP
#define STREAM_IO_HPP

#include <cstdio>
#include <string>

typedef FILE *FilePtr;

class StreamRedirect {
 public:
    StreamRedirect(const std::string &in, const std::string &out) {
        if (!in.empty()) { freopen(in.data(), "r", stdin); }
        if (!out.empty()) { freopen(out.data(), "w", stdout); }
    }
    StreamRedirect(const StreamRedirect &other) = default;

    ~StreamRedirect() {
        fclose(stdin);
        fclose(stdout);
    }
};

#endif  // STREAM_IO_HPP
